<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加书籍</title>
    <script type="text/javascript" src="/js/jquery-3.2.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("#submit").click(function() {
                var wangwenboId=$("#wwbId").val();
                var wangwenboName=$("#wwbName").val();
                var wangwenboPrice=$("#wwbPrice").val();
                var wangwenboCover=$("#wwbCover").val();
                if ($.trim(wangwenboName)=='') {
                    alert("书籍名称不能为空！");
                    return;
                }
                var wangwenboParams = {
                    wwbId:wangwenboId,
                    wwbName:wangwenboName,
                    wwbPrice:wangwenboPrice,
                    wwbPath:wangwenboCover
                };
                $.post({
                    url:"./wwbInsertBook",
                    // 此处需要告知传递参数类型为JSON，不能缺少
                    contentType:"application/json",
                    // 将JSON转化为字符串传递
                    data:JSON.stringify(wangwenboParams),
                    // 成功后的方法
                    success:function(result){
                        console.log(result)
                        if(result.wwbId == null) {
                            alert("插入失败");
                            return;
                        }
                        alert("插入成功"+result.wwbName+">>"+result.wwbPrice);
                        window.location.href="./Details";
                    }
                });
            });
        });
    </script>
</head>
<body>
<div align="center">
    <h2>添加书籍信息界面</h2>
    <hr>
    <form method="post" action="./upload/wwbMultipart" enctype="multipart/form-data">
        <table>
            <tr>
                <td>书籍编号：</td>
                <td><input name="wwbId" id="wwbId"></td>
            </tr>
            <tr>
                <td>书籍名称：</td>
                <td><input name="wwbName" id="wwbName"></td>
            </tr>
            <tr>
                <td>书籍价格：</td>
                <td><input name="wwbPrice" id="wwbPrice"></td>
            </tr>
            <tr>
                <td>封皮:</td>
                <td><input type="file" name="wwbCover" id="wwbCover" value="请选择上传的文件"/></td>
            </tr>
        </table>
        <table>
            <tr>
                <td><input type="submit" id="submit" value="提交"></td>
                <td><input type="reset" name="reset" value="重置"></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>